<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="js/jquery-ui.css">
<title>学生管理</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript">
	function bjChange(bjId) {
		if(bjId==0){
			$('#myTable').empty();
		}else{
			$('#myTable').load('xuesheng?method=table&id='+bjId);
		}
	}
	function add() {
		window.location="xuesheng?method=add&bjId="+$('#bj').val();
	}
	function del(id) {
		if(confirm('是否要删除这条记录？')){
			window.location="xuesheng?method=delete&id="+id;
		}
	}
	function update(id) {
		window.location="xuesheng?method=update&id="+id;
	}
	function fandeng() {
		window.location="login.jsp"
	}	
	function fanzhu() {
		window.location="main?method=main"
	}	
</script>

</head>
<body>
<div class="aaa">
	<p>	
	<label>班级：</label>
	<select id="bj" onchange="bjChange(this.value)" >
		<option value="0" >请选择班级</option>
		<c:forEach items="${bjs}" var="bj">
			<option value ="${bj.id }">${bj.name}</option>
		</c:forEach>	
	</select>
	
	</p>
<div id="myTable">
		<c:if test="${bjId!=null}">
			<button type="button" onclick="add()" class="push_button red">新增</button>
			<table border="1">
				<tr>
					<th>学号</th>
					<th>姓名</th>
					<th>密码</th>
					<th colspan="2">操作</th>
				</tr>
				<c:forEach items="${students}" var="s">
					<tr>
						<td>${s.stuNo}</td>
						<td>${s.name}</td>
						<td>${s.password}</td>
						<td><button type="button" onclick="update(${s.id})">修改</button></td>
						<td><button onclick="javascript:del(${s.id})">删除</button></td>
				</tr>
				</c:forEach>
			</table>
		</c:if>
	<div class="bbb">
	<button onclick="fandeng()" class="btn">返回登录页面</button>
	<button onclick="fanzhu()" class="btn">返回主页面</button>
	</div>
	</div>
</div>
</body>
</html>